{extend name="base/base" /}

{block name="content"}
        <form class="layui-form" id="edit_form" onsubmit="return false">
          <div class="layui-form-item">
            <label class="layui-form-label">客服1：</label>
            <div class="layui-input-inline">
                <img src="" style="width: 100px;height: 100px" id="show_upload_img1">
                <input type="hidden" name="pic1" id='pic1' value="{$pic1 ?? ''}">
             </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" class="layui-btn" id="upload1">
                <i class="layui-icon"></i>上传图片
              </button>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">客服2：</label>
            <div class="layui-input-inline">
                <img src="" style="width: 100px;height: 100px" id="show_upload_img2">
                <input type="hidden" name="pic2" id='pic2' value="{$pic2 ?? ''}">
             </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" class="layui-btn" id="upload2">
                <i class="layui-icon"></i>上传图片
              </button>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-filter="formDemo" onclick="ajax()">立即提交</button>
              <button onclick="cancel()" class="layui-btn layui-btn-primary">取消</button>
            </div>
          </div>
        </form>
{/block}
{block name="script"}
<script>
    layui.use('upload', function(){
      var upload = layui.upload;
      upload.render({
      elem: '#upload1'
       ,url: '{:C("system_url")."/api/Upload/upload_img"}'
      ,before:function(){
        var index = layer.msg('正在拼命处理...' , {
          icon: 16 ,
          shade: 0.6 ,
          time: 0 ,
        });
      }
      ,done: function(res){
        if(res.code==0){
          $("#show_upload_img1").attr('src',res.data);
          $("#pic1").val(res.data);
          layer.msg('上传图片成功');
        } else {
          layer.msg('上传图片失败');
        }
      }
      }); 
       upload.render({
      elem: '#upload2'
      ,url: '{:C("system_url")."/api/Upload/upload_img"}'
      ,before:function(){
        var index = layer.msg('正在拼命处理...' , {
          icon: 16 ,
          shade: 0.6 ,
          time: 0 ,
        });
      }
      ,done: function(res){
        if(res.code==0){
          $("#show_upload_img2").attr('src',res.data);
          $("#pic2").val(res.data);
          layer.msg('上传图片成功');
        } else {
          layer.msg('上传图片失败');
        }
      }
      });     
    });
    function ajax(){
      var post_data = $("#edit_form").serialize();
      $.ajax({
          url:"{:url('admin/System/kf')}",
          type:"POST",
          data:post_data,
          success:function(ret){
              if (ret.code == 0) {
                layer.msg('添加成功');
                window.location.reload();
              }
              if (ret.code == 1) {
                  layer.msg(ret.msg);
              }
          }
      });
    }
  //   function upload_img(el){
  //     var file = el.files[0];
  //     $("#show_upload_img").attr('src',URL.createObjectURL(file));
  //   }
  //   function ajax(){
  //     var post_data = new FormData(document.getElementById("ajaxform"));
  //     $.ajax({
  //       url:'',
  //       type:'POST',
  //       data:post_data,
  //       processData:false,
  //       contentType:false,
  //       success:function(ret){
  //         if (ret.code == 1) {
  //           window.location.href=document.referrer;
  //         } else {
  //           layer.msg(ret.msg);
  //         }
  //       }
  //     });
  //   }
    function cancel(){
    window.location.href=document.referrer;
  }
</script>
{/block}
